package com.wolfsea.defineviewgrouppaper
import android.content.Context
import android.content.res.Resources

/**
 *@desc  扩展方法
 *@author liuliheng
 *@time 2023/1/29  19:04
 **/

/*
 * 获取顶部状态栏高度
 * */
fun Resources.getStatusBarHeight(): Int {
    val resourcesId = getIdentifier("status_bar_height", "dimen","android")
    return getDimensionPixelOffset(resourcesId)
}

/*
* 获取底部状态栏高度
* */
fun Resources.getNavigationBarHeight(): Int {
    val resourcesId = getIdentifier("navigation_bar_height", "dimen","android")
    return getDimensionPixelOffset(resourcesId)
}

/*
* 判断底部导航栏是否存在
* */
fun Context.checkDeviceHasNavigationBar(): Boolean {
    var hasNavigationBar = false
    val resourcesId = resources.getIdentifier("config_showNavigationBar", "bool", "android")
    if (resourcesId > 0) {
        hasNavigationBar = resources.getBoolean(resourcesId)
    }
    try {
        val systemPropertiesClass = Class.forName("android.os.SystemProperties")
        val method = systemPropertiesClass.getMethod("get", String::class.java)
        val navBarOverride = method.invoke(systemPropertiesClass, "qemu.hw.mainkeys") as String
        if ("1" == navBarOverride) {
            hasNavigationBar = false
        } else if ("0" == navBarOverride) {
            hasNavigationBar = true
        }
    } catch (e: Exception) {
    }
    return hasNavigationBar
}